Add polyglot interaction service APIs#17874
Conversation
Expose IInteractionService through polyglot AppHost service providers and add ATS-friendly prompt wrappers for interaction prompts. Update generated SDK snapshots and compile-time validation apps across TypeScript, Python, Go, and Java. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17874Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17874" |
There was a problem hiding this comment.
Pull request overview
This PR exposes Aspire’s IInteractionService through ATS/polyglot callback IServiceProvider instances, enabling TypeScript/Python/Go/Java/Rust AppHosts to prompt users (confirmation, message box, input dialogs, notifications) via generated SDK wrappers.
Changes:
- Added new ATS exports and DTO wrappers for interaction capabilities (availability + prompt APIs) and exported
IInteractionServicein ATS type mappings. - Updated polyglot compile-time validation AppHosts (TS/Python/Go/Java) to resolve and call the interaction service from callback service providers.
- Regenerated/updated ATS baselines and multi-language generated SDK snapshots; adjusted Java generator option-parameter naming (
options→optionsBag) to keep generated overloads idiomatic.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.mts | Adds interaction service resolution and prompt API calls for TS compile-time validation. |
| tests/PolyglotAppHosts/Aspire.Hosting/Python/apphost.py | Adds interaction service resolution and prompt API calls for Python compile-time validation. |
| tests/PolyglotAppHosts/Aspire.Hosting/Java/AppHost.java | Adds interaction service resolution and prompt API calls for Java compile-time validation. |
| tests/PolyglotAppHosts/Aspire.Hosting/Go/apphost.go | Adds interaction service resolution and prompt API validation helper for Go compile-time validation. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts | Updates TS generated SDK snapshot with interaction service handles, DTOs, enums, and service-provider accessors. |
| tests/Aspire.Hosting.CodeGeneration.Rust.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.rs | Updates Rust generated SDK snapshot with interaction service wrappers, DTOs, and enums. |
| tests/Aspire.Hosting.CodeGeneration.Python.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.py | Updates Python generated SDK snapshot with interaction service wrappers/DTOs and service-provider accessor. |
| tests/Aspire.Hosting.CodeGeneration.Java.Tests/Snapshots/AtsGeneratedAspire.verified.java | Updates Java generated SDK snapshot (including option overload parameter naming changes). |
| tests/Aspire.Hosting.CodeGeneration.Go.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.go | Updates Go generated SDK snapshot with interaction service wrappers/DTOs and service-provider accessor. |
| src/Aspire.Hosting/Ats/InteractionExports.cs | Introduces ATS exports for IInteractionService + ATS-friendly DTO wrappers for polyglot SDKs. |
| src/Aspire.Hosting/Ats/AtsTypeMappings.cs | Exports IInteractionService as an ATS handle type. |
| src/Aspire.Hosting/api/Aspire.Hosting.ats.txt | Updates ATS baseline with interaction capabilities, DTOs, and MessageIntent. |
| src/Aspire.Hosting.CodeGeneration.Java/AtsJavaCodeGenerator.cs | Renames generated options overload parameter from options to optionsBag for Java output. |
Update TypeScript code generation so nullable ATS DTO members, including interaction result data, are emitted with null in their TypeScript types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Is the code sample right? |
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns>The input interaction result.</returns> | ||
| [AspireExport("promptInputWithInput", MethodName = "promptInputWithInputAsync")] | ||
| public static async Task<InputInteractionResult> PromptInputWithInputAsync( |
There was a problem hiding this comment.
Ah, I see. No overloads.
IMO remove existing PromptInputAsync, it's just a helper method, and rename this to PromptInputAsync.
| InteractionInput input, | ||
| InputsDialogInteractionOptions? options = null, |
There was a problem hiding this comment.
How do you decide whether to expose a custom export type or not? I'm curious why the options needs one and InteractionInput does.
|
Have you tested this works IRL? It's tough to unit test this as it shows up as UI in the dashboard. I'd like to see a TypeScript playground app have a resource with a command, and in that command it prompts for input. The input should be a choice, and use DynamicLoading to populate options. The callback should wait for a second and then set some option values. And have validation of the input values. After the input returns then get the value from the input and write to logging (or return it with command result). That would excerise all the most complex parts of the interaction service. |
| [AspireDto] | ||
| internal sealed class InputsDialogInteractionOptions : InteractionOptions | ||
| { | ||
| internal PublicInputsDialogInteractionOptions ToInputsDialogInteractionOptions() |
There was a problem hiding this comment.
This is missing the validationcallback property
There was a problem hiding this comment.
There is a problem here with that one. It's not working with DTOs ... for the reason I explained on the other issue with DTOs, can't serialize behavior either.
Will think about a solution, might have to refactor what is exposed use handles instead. I understand it's required for dynamic inputs. validationCallback is the remaining issue. Everything else seems to work (including loadCallback which is surprising).
Move validation AppHost service-provider access until after builder.build() and document that the execution context service provider is populated during build. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
❓ CLI E2E Tests unknown — 113 passed, 0 failed, 2 unknown (commit View all recordings
📹 Recordings uploaded automatically from CI run #26990450410 |
|
Replaced by #17959 which is not using DTOs where we need to use callbacks (dynamic loading, validation) |
Description
Expose Aspire's interaction service to polyglot AppHosts through callback
IServiceProviderinstances, matching the existing pattern for other services available from callback service providers. Polyglot integration authors can now resolve the interaction service and prompt users from TypeScript, Python, Go, and Java AppHosts.This adds ATS-friendly interaction wrappers for availability checks, confirmation prompts, message boxes, single input prompts, multiple input prompts, and notifications. The wrappers return non-generic result DTOs so the generated SDKs do not need to model
InteractionResult<T>directly. The generated SDK baselines and compile-time validation AppHosts were updated across TypeScript, Python, Go, Java, and Rust, and Java option DTO names were kept idiomatic without aDtosuffix.User-facing usage
TypeScript AppHosts can resolve and use the interaction service from callback service providers:
Java AppHosts get natural generated option names:
Validation:
RunAnalyzers=false dotnet run --project src/Aspire.Cli/Aspire.Cli.csproj -- sdk dump --format ci --output src/Aspire.Hosting/api/Aspire.Hosting.ats.txtdotnet testfor the ATS scanner tests and TypeScript, Go, Python, Java, and Rust code generation test projectstests/PolyglotAppHosts/Aspire.HostingTypeScript, Python, Go, and Java AppHosts afteraspire restoreFixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?